package com.example.service;

import com.example.entity.Account;
import com.example.entity.Positions;
import com.example.mapper.PositionsMapper;
import com.example.utils.TokenUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 职位类型
 **/
@Service
public class PositionsService {

    @Resource
    private PositionsMapper positionsMapper;

    /**
     * 新增
     */
    public void add(Positions positions) {
        Account currentUser = TokenUtils.getCurrentUser();
        positionsMapper.insert(positions);
    }

    /**
     * 删除
     */
    public void deleteById(Integer id) {
        positionsMapper.deleteById(id);
    }

    /**
     * 批量删除
     */
    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            positionsMapper.deleteById(id);
        }
    }

    /**
     * 修改
     */
    public void updateById(Positions positions) {
        positionsMapper.updateById(positions);
    }

    /**
     * 根据ID查询
     */
    public Positions selectById(Integer id) {
        return positionsMapper.selectById(id);
    }
    /**
     * 查询所有
     */
    public List<Positions> selectAll(Positions positions) {
        return positionsMapper.selectAll(positions);
    }

    /**
     * 分页查询
     */
    public PageInfo<Positions> selectPage(Positions positions, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Positions> list = positionsMapper.selectAll(positions);
        return PageInfo.of(list);
    }

    /*根据职位类型Id查职位名称*/
    public List<Positions> selectByPositionTypeId(Integer positionTypeId) {
        return positionsMapper.selectByPositionTypeId(positionTypeId);
    }
}